import config from 'config';
import httpFetch from 'share/httpFetch';
import configureStore from "stores";
import errorMessage from "share/errorMessage";

export default {
  //客户类型信息详情
  getCustomerDetail(id){
    return httpFetch.get(`${config.baseUrl}/api/customer?id=${id}`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取客户主体列表
  getCustomerList(params) {
    return httpFetch.get(`${config.baseUrl}/api/customer/list`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //新增客户主体
  addCustomerObject(params, roleType) {
    return httpFetch.post(`${config.baseUrl}/api/customer/create${roleType}`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //编辑客户主体
  editCustomerObject(params, roleType) {
    return httpFetch.put(`${config.baseUrl}/api/customer/update${roleType}`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取已分配公司列表
  getCompanyList(customerId) {
    return httpFetch.get(`${config.baseUrl}/api/customer/company/list?customerId=${customerId}`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //分配部分公司
  assignPartCompany(params) {
    return httpFetch.post(`${config.baseUrl}/api/customer/company/assign/batch`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //启用禁用公司
  enableCompany(params) {
    return httpFetch.post(`${config.baseUrl}/api/customer/company/update`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取银行账户详情
  getBankAccountDetail(id) {
    return httpFetch.get(`${config.baseUrl}/api/customer/bank?id=${id}`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //新增客户银行账户
  addBankAccount(params) {
    return httpFetch.post(`${config.baseUrl}/api/customer/bank/create`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //编辑客户银行账户
  editBankAccount(params) {
    return httpFetch.put(`${config.baseUrl}/api/customer/bank/update`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取银行列表
  getBankAccountList(customerId, params) {
    return httpFetch.get(`${config.baseUrl}/api/customer/bank/list?customerId=${customerId}`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //主账户校验
  checkoutPrimaryFlag(customerId) {
    return httpFetch.get(`${config.baseUrl}/api/customer/bank/primary/validation?customerId=${customerId}`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取账户标志
  getSymbols() {
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/template/by/type?enabled=true&type=2216`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },

  //获取所属公司
  getCompanys(key) {
    return httpFetch.get(`${config.baseUrl}/api/company/search/by/authority/distribute?resourceId=&key=${key}`)
      .catch((err) => {
        errorMessage(err.response);
        throw(err);
      })
  },
}

